home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DRIVES.SWG / 0008_DRIVES3.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  1KB  |  47 lines

  1. { JW│ How do I detect active drives in Pascal?  My Program would crash if you
  2.    │ Typed in a non-existent drive as either source or destination.
  3.  
  4. Here's the method I use:
  5. }
  6. Uses
  7.   Dos;
  8.  
  9. Var
  10.   Isthere : Boolean;
  11.  
  12. Function ChangeDrive( drv: Char ): Boolean;
  13. (*
  14. Takes drive letter as parameter, returns True if change
  15. succeeded, False if change failed (invalid drive)
  16. *)
  17. Var
  18.   Regs:   Dos.Registers;
  19.   NewDrv: Byte;
  20. begin
  21. (* Calculate drive code For desired drive *)
  22.   NewDrv := orD( UpCase( drv ) ) - orD( 'A' ); (* A: = 0 *)
  23.  
  24. (* Change drive *)
  25.   Regs.DL := NewDrv;
  26.   Regs.AH := $0E;            (* Function 0Eh: Select Disk *)
  27.   MSDos( Regs );
  28.  
  29. (* See if the change 'took' *)
  30.   Regs.AH := $19; (* Function 19h:  Get current drive *)
  31.   MSDos( Regs );
  32.   ChangeDrive := (Regs.AL = NewDrv);
  33. end; (* ChangeDrive *)
  34.  
  35. begin
  36.   isthere := ChangeDrive('a');
  37.   Writeln ('a: ',isthere);
  38.   isthere := ChangeDrive('b');
  39.   Writeln ('b: ',isthere);
  40.   isthere := ChangeDrive('c');
  41.   Writeln ('c: ',isthere);
  42.   isthere := ChangeDrive('d');
  43.   Writeln ('d: ',isthere);
  44.   isthere := ChangeDrive('e');
  45.   Writeln ('e: ',isthere);
  46. end.
  47.